<?php
require_once("../../../config.inc.php");
require_once("../../../app/_inc/include.php");
require_once "../_inc/procFunction.php";

$errMsg = sxREQ('msg');
$module = sxREQ('mod');
$functionalArea = sxREQ('fa');
if($module==''){
	$url = $_SESSION[USEROBJ]->getHistory(-1, true).
		"&msg=".urlencode(_t("variabile 'mod' non passata")); 
	serverRedir($url);
}
if($functionalArea==''){
	$url = $_SESSION[USEROBJ]->getHistory(-1, true).
		"&msg=".urlencode(_t("variabile 'fa' non passata")); 
	serverRedir($url);
}
if (sxREQ('del')=='yes') {
	$errMsg .= functionalAreaDel();
}
//functional-area read
$sSQL = "SELECT * FROM functional_area WHERE module = '$module' AND functional_area = '$functionalArea'";
$objSDAO->query($sSQL,"mod");
if(!$row = $objSDAO->fetch("mod")) {
	$url = $_SESSION[USEROBJ]->getHistory(-1, true).
		"&msg=".urlencode(_t("area funzionale '%s' inesistente",$module.'.'.$functionalArea)); 
	serverRedir($url);
}
$description = $row['description'];
$note = $row['note'];
//module read
$sSQL = "SELECT description FROM module WHERE module = '$module'";
$objSDAO->query($sSQL,"mod");
if(!$row = $objSDAO->fetch("mod")) {
	$url = $_SESSION[USEROBJ]->getHistory(-1, true).
		"&msg=".urlencode(_t("mudule '%s' missing",$module)); 
	serverRedir($url);
}
//sub-module list
$sSQL = "SELECT sm.*
		FROM sub_module sm 
		WHERE sm.module='$module' AND sm.functional_area = '$functionalArea'
		ORDER BY sm.sub_module";
$objSDAO->query($sSQL, "submod");

$aOpz = array("kMenu"=>'pro.mod');
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript">
	function confDelFA(){
		if (confirm("Confermi l'eliminreqtype dell'area funzionale ?")) {
			document.location.href = "functionalAreaView.php?del=yes<?="&mod=$module&fa=$functionalArea&xsn=".XSN?>";
		}
	}
</script>
  
<?php
echo(bodyHTML($aOpz));
echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");

echo getModHeader($module);

$aCmd = array(
					"newsm"=>array("pag"=>"subModIns.php?mod=$module&fa=$functionalArea",
										"title"=>_t("add sub-module"),
										"text"=>_t("new sub-module"),'align'=>'R'
										),
					"modfa"=>array("pag"=>"functionalAreaMod.php?mod=$module&fa=$functionalArea",
										"title"=>_t("changea functional area"),
										"text"=>_t("change")
										),
					"delfa"=>array("pag"=>"javascript:confDelFA()",
										"title"=>_t("delete functional-area"),
										"text"=>_t("delete")
										),
					"back"=>array("pag"=>$objUser->getHistory(-1,false),
										"title"=>"back",
										"text"=>"back"
										)
					);
echo(commandsHTML($aCmd));	
echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");
echo("<tr>" .
			"<td class=\"titl01\" colspan='2'>Functional-Area</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\" width='15%'>"._t("Name")."</td>" .
			"<td class=\"text01\" width='85%'>$functionalArea</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Description")."</td>" .
			"<td class=\"text01\" colspan='1'>$description</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Note")."</td>" .
			"<td class=\"text01\" colspan='1'><pre class='text01'>$note</pre></td>" .
		"</tr>\n");
echo("</table>");

echo("<table class='tabl01' width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
echo("<tr>" .
		"<td class=\"titl01\"colspan=\"3\">List of sub-modules</td>" .
	"</tr>\n");
echo("<tr>" .
		"<td class=\"tabh01\" width=\"15%\">"._t('Sub-module')."</td>" .
		"<td class=\"tabh01\" width=\"85%\">"._t('Description')."</td>" .
	"</tr>\n");	
while($row = $objSDAO->fetch("submod")){
			$numElem ++;
			echo("<tr>" .
					"<td class=\"text01\" valign='top'><a class=\"text01\" ".
						goToPag("subModView.php?mod=".$row["module"]."&sub=".$row["sub_module"]."&xsn=".XSN).
						" title=\""._t("visualizza ")."'".sxHE($row["description"])."'\">".
						$row["sub_module"]."</a></td>\n" .
					"<td class=\"text01\" valign='top'>".sxHE($row["description"])."</td>" .
				"</tr>\n");
}
echo("</table>\n");

echo(commandsHTML($aCmd));
echo("<div id=\"messArea\" class=\"mess01\">$errMsg</div>");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());
exit();

function functionalAreaDel(){
	global $objSDAO;
	$errMsg = "";
	$sSQL = "DELETE FROM functional_area " .
				" WHERE module='".sxRAS("mod")."' " .
					" AND functional_area = '".sxRAS("fa")."'";	
	$objSDAO->query($sSQL,"ins");
	$url = $_SESSION[USEROBJ]->getHistory(-1, true);
	serverRedir($url);
	exit;
}
